package com.suixun.controller;

import com.github.pagehelper.PageInfo;
import com.suixun.controller.base.BaseController;
import com.suixun.domain.Instructions;
import com.suixun.service.InstructionsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/instructions")
public class InstructionsController extends BaseController {
    @Resource
    private InstructionsService instructionsService;

    /**
     * 分页
     * @param page
     * @param size
     * @param title
     * @param type
     * @return
     */
    @GetMapping("/page/{page}/{size}")
    public Object page(@PathVariable Integer page, @PathVariable Integer size, String title, Integer type) {
        return success(instructionsService.pageInstructions(page, size, title, type, 1));
    }

    @PostMapping("/add")
    public Object add(Instructions instructions, Boolean isTop) {
       instructionsService.insert(instructions, isTop);
       return success();
    }

    @PostMapping("/update")
    public Object update(Instructions instructions, Boolean isTop) {
        instructionsService.update(instructions, isTop);
        return success();
    }

    @GetMapping("/get/{id}")
    public Object page(@PathVariable Integer id) {
        return success(instructionsService.getById(id));
    }

    @PostMapping("/delete")
    public Object delete(String ids) {
        instructionsService.delete(ids);
        return success();
    }
}
